package chapter06;

import java.util.concurrent.TimeUnit;

/**
 * @author chisheng
 * @since 2021-11-11
 */
public class ThreadGroupPriority {

    @SuppressWarnings("all")
    public static void main(String[] args) throws InterruptedException {
        ThreadGroup myGroup = new ThreadGroup("myGroup");
        Thread myThread = new Thread(myGroup, () -> {
            while (true) {
                try {
                    TimeUnit.SECONDS.sleep(1);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }, "myThread");
        myThread.start();

        TimeUnit.MILLISECONDS.sleep(2);

        System.out.println("myGroup.getMaxPriority(): " + myGroup.getMaxPriority());
        System.out.println("myThread.getPriority(): " + myThread.getPriority());

        myGroup.setMaxPriority(3);
        System.out.println("myGroup.getMaxPriority(): " + myGroup.getMaxPriority());
        System.out.println("myThread.getPriority(): " + myThread.getPriority());

        // myGroup.getMaxPriority(): 10
        // myThread.getPriority(): 5
        // myGroup.getMaxPriority(): 3
        // myThread.getPriority(): 5
    }

}
